package com.heima.srevice;

import com.baomidou.mybatisplus.extension.service.IService;
import com.heima.domain.dto.OrderDetailDTO;
import com.heima.domain.po.Item;
import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

import java.util.List;

@LocalTCC
public interface ItemFreezeService extends IService<Item> {
    /**
     * @localTCC:执行TCC的接口上：Impl
     * @TwoPhaseBusinessAction(name = "deductStock",commitMethod = "confirm",rollbackMethod = "cancel")
     * 1、Try业务处理
     * 2、Confirm提交业务处理
     * 3、Cancel回滚
     */
    @TwoPhaseBusinessAction(name = "deductStock",commitMethod = "confrim",rollbackMethod = "cancel")
    void deductStock(@BusinessActionContextParameter("items")List<OrderDetailDTO> items);

    /**
     * Confirm 提交业务处理
     */
    boolean confrim(BusinessActionContext ctx);

    /**
     * Cancel回滚
     */
    boolean cancel(BusinessActionContext ctx);
}
